package com.weichen.studentgameexchange.common.exception;

import com.weichen.studentgameexchange.common.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 功能：
 * 作者：惟尘
 * 日期：2025/1/23 10:42
 */
@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(ServiceException.class)
    @ResponseBody  //将对象转为json对象
    public Result serviceException(ServiceException e) {
        return Result.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody  //将对象转为json对象
    public Result globalException(Exception e) {
        e.printStackTrace();
        return Result.error("500", "系统错误！");
    }

}
